<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* nums里有重复元素，因此我们推入的时候需要去重 */
            var subsetsWithDup = function (nums) {
                nums.sort((a, b) => a - b)
                let res = []
                let map = new Map()
                function backTacking(path, start) {
                    if (start > nums.length) return
                    //判断是否重复  [1,2,2] [2,1,2]这种情况
                    let str = path.join("")
                    if (!map.has(str)) {
                        map.set(str, 1)
                        res.push([...path])
                    }
                    for (let i = start; i < nums.length; i++) {
                        path.push(nums[i])
                        backTacking(path, i + 1)
                        path.pop()
                    }
                }
                backTacking([], 0)
                return res
            }
        </script>
    </body>
</html>
